/**
 * 状态栏高度
 */
export function cxStatusBarHeight() {
	return uni.getSystemInfoSync().statusBarHeight;
}



/**
 * navbar高度
 */
export function cxNavBarHeight() {

	return (uni.getSystemInfoSync().statusBarHeight + 44) * 2;
}

/**
 * bottom 安全距离
 */
export function cxBottomSafeHeight() {
	const safeArea = uni.getSystemInfoSync().safeArea;
	const bottomArea = (safeArea.bottom - safeArea.height);
	return bottomArea;
}

/**
 * 胶囊宽度+右边距 即导航栏右侧安全宽度
 */
export function cxNavRightSafeWidth() {
	const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
	const width = 750 - menuButtonInfo.left * 2;
	return width;
}


export function cxScreenWidth() {
	const width = uni.getSystemInfoSync().screenWidth;
	return width;
}

export function cxScreenHeight() {
	const height = uni.getSystemInfoSync().screenHeight;
	return height;
}
export function cxGetCurrentPageOption() {
	let pages = getCurrentPages();
	let currentPage = pages[pages.length - 1];
	let option = currentPage.options;
	return option;
}

// 通过margin 获取每一个值
export function cxGetMarginArr(margin) {
	let arr = [];
	let temp = margin.split(" ");
	if (temp.length == 1) {
		arr = arr.concat([temp[0], temp[0], temp[0], temp[0]])
	} else if (temp.length == 2) {
		arr = arr.concat([temp[0], temp[1], temp[0], temp[1]])
	} else if (temp.length == 3) {
		arr = arr.concat([temp[0], temp[1], temp[2], temp[1]])
	} else {
		arr = arr.concat([temp[0], temp[1], temp[2], temp[3]])
	}

	return arr;
}




/**
 * 当前版本号
 */
export function getCurrentVersion() {
	const miniProgram = uni.getAccountInfoSync();
	let version = miniProgram.miniProgram.version;

	return version;
}


/**
 * @name {String} 从链接中获取参数 
 * @param {Object} url链接
 */
export function cxGetQueryString(url) {
	// \w+ 表示匹配至少一个(数字、字母及下划线), [\u4e00-\u9fa5]+ 表示匹配至少一个中文字符
	let pattern = /(\w+|[\u4e00-\u9fa5]+)=(\w+|[\u4e00-\u9fa5]+)/ig;
	let result = {};
	url.replace(pattern, ($, $1, $2) => {
		result[$1] = $2;
	})
	return result

}